package com.example.test2.view;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;

import com.example.test2.R;
import com.example.test2.activity.AddBuyActivity;
import com.example.test2.activity.AddClothesActivity;
import com.example.test2.databinding.DialogSendBinding;

public class SendDialog extends Dialog implements View.OnClickListener {
    private DialogSendBinding viewBinding;
    private Context context;

    public SendDialog(@NonNull Context context) {
        super(context);
        this.context=context;
    }

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //设置一个布局
        viewBinding = DialogSendBinding.inflate(getLayoutInflater());
        setContentView(viewBinding.getRoot());
        //按空白处不能取消动画
        setCanceledOnTouchOutside(true);
        //按返回键不消失
        setCancelable(false);
        //设置window背景，默认的背景会有Padding值，不能全屏。当然不一定要是透明，你可以设置其他背景，替换默认的背景即可。
        getWindow().setBackgroundDrawable(new ColorDrawable(getContext().getResources().getColor(R.color.transparent)));
        //一定要在setContentView之后调用，否则无效
        getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        initView();
        initLayout();//避免布局被删掉
    }

    private void initView() {
        viewBinding.ivClose.setOnClickListener(this);
        viewBinding.llSendCommodity.setOnClickListener(this);
        viewBinding.llSendPurchase.setOnClickListener(this);
    }


    protected int initLayout() {
        return R.layout.dialog_send;
    }
    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_close:
                dismiss();
                break;
            case R.id.ll_send_commodity:
                dismiss();
                context.startActivity(new Intent(context, AddClothesActivity.class));
                break;
            case R.id.ll_send_purchase:
                dismiss();
                context.startActivity(new Intent(context, AddBuyActivity.class));
                break;
        }
    }

}
